package com.yxhl.zoume.core.user.presenter;

import android.content.Context;

import com.yxhl.zoume.common.presenter.BasePresenter;
import com.yxhl.zoume.common.presenter.IPresenter;
import com.yxhl.zoume.common.ui.view.BaseView;
import com.yxhl.zoume.core.user.view.UserCenterHomeView;
import com.yxhl.zoume.data.http.rest.param.usercenter.LogoutParam;
import com.yxhl.zoume.data.http.rest.response.usercenter.LogoutResponse;
import com.yxhl.zoume.domain.interactor.ZMSubscriber;
import com.yxhl.zoume.domain.interactor.usercenter.LogoutUseCase;

import javax.inject.Inject;

/**
 * Created by vhawk on 16/4/12.
 */
public class UserCenterPresenter extends BasePresenter implements IPresenter {

    @Inject
    LogoutUseCase useCase;

    private UserCenterHomeView mUserCenterHomeView;

    @Inject
    public UserCenterPresenter(Context context) {
        super(context);
    }

    @Override
    public void onResume() {

    }

    @Override
    public void onPause() {

    }

    @Override
    public void onDestroy() {
        useCase.unsubscribe();
    }

    @Override
    public void attachView(BaseView view) {
        this.mUserCenterHomeView = (UserCenterHomeView) view;
    }

    /**
     * 退出登录
     */
    public void logout() {

        LogoutParam param = new LogoutParam(getMobile(), getToken());
        useCase.execute(param, new ZMSubscriber<LogoutResponse>() {
            @Override
            public void onCompleted() {
                super.onCompleted();
                mUserCenterHomeView.logoutResult();
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
                mUserCenterHomeView.logoutResult();
            }

        });
    }
}
